Chapter 14 - Lifecycle Management
Ignoring changes and not updating the terraform when it doesn't need to be updated. https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle
- create_before_destroy - creates a new resource before destroying the old one.
- prevent_destroy - don't destroy these resources
- ignore_changes - ignores some of the changes of the resource
- replace_triggered by - (1.2+) - if something is changed somewhere else, then this resource will be replaced based on that trigger.
Preconditions and postconditions
resource "aws_instance" "example" {
instance_type = "t2.micro"
ami = "ami-abc123"
lifecycle {
# The AMI ID must refer to an AMI that contains an operating system
# for the `x86_64` architecture.
precondition {
condition = data.aws_ami.example.architecture == "x86_64"
error_message = "The selected AMI must be for the x86_64 architecture."
}
}
}